package code03_分支结构;

import java.util.Scanner;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月17日9:38
 */
public class Test08_改造练习 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入年份:");
        int year = sc.nextInt();
        System.out.print("请输入月份:");
        int month = sc.nextInt();
        // 定义一个用于接收天数的变量
        int day = 0;
        if (year >= 1970 && month >= 1 && month <= 12) {
            switch (month) {
                case 2:
                    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                        day = 29;
                    } else {
                        day = 28;
                    }
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    day = 30;
                    break;
                default:
                    day = 31;
                    break;
            }
            System.out.println(year + "年" + month + "月共有" + day + "天");
        } else {
            System.out.println("错误:您输入的年份或月份有误,请重新输入");
        }
    }
}